import request from "."
import type { PageInfo, ApiPageResult, ApiResult } from "@/lib/model"

export default {
    list() {
        return request.getJson<{}, ApiResult<Array<{ label: string, value: string }>>>("/api/scope/list", {})
    },
    page(dto: ApiScopeSearch) {
        return request.getJson<ApiScopeSearch, ApiPageResult<ApiScopeSearch>>("/api/scope", dto)
    },
    delete(ids: number[]) {
        return request.deleteJson<number[], ApiResult>("/api/scope", ids)
    },
    save(dto: ApiScopeItem) {
        return request.postJson<ApiScopeItem, ApiResult>("/api/scope", dto)
    },
}

export interface ApiScopeSearch extends PageInfo {
    name?: string
}

export interface ApiScopeItem {
    "id"?: number
    "enabled"?: boolean
    "name"?: string
    "displayName"?: string
    "description"?: string
    "required"?: boolean
    "emphasize"?: boolean
    "showInDiscoveryDocument"?: boolean
    "userClaims"?: userClaim[],
    "properties"?: Property[]
}

export interface Property {
    "id"?: number,
    "key"?: string
    "value"?: string
    "scopeId"?: number
}

export interface userClaim {
    "id"?: number
    "type"?: string
    "scopeId"?: number
}
